package com.itcoon.transform4j.demo.web.controller;

import com.itcoon.common.web.core.response.ApiResponse;
import com.itcoon.transform4j.demo.web.vo.*;
import com.itcoon.transform.starter.Transformer;
import com.itcoon.transform4j.demo.domain.Student;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

@Api(tags = "01_assemble_基础篇", description = "assemble 一对一编集测试, 属性映射")
@RestController
@RequestMapping("/api")
public class BaseAssembleController {

    @ApiOperation("获取学生信息(根据定义的接口编集一个普通类对象)")
    @GetMapping("/student")
    public ApiResponse<StudentVIO> getStudent(){
        Student student = new Student();
        student.setSid(1L);
        student.setName("张三");
        StudentVIO studentVIO = Transformer.to(StudentVIO.class).apply(student).done();
        return ApiResponse.createSuccess(studentVIO);
    }



    @ApiOperation("获取学生信息(根据定义的接口多重编集一个普通类对象)")
    @GetMapping("/student2")
    public ApiResponse<StudentVIO2> getStudent2(){
        Student student = new Student();
        student.setSid(1L);
        student.setName("张三");
        StudentVIO studentVIO = Transformer.to(StudentVIO.class).apply(student).done();
        StudentVIO2 studentVIO2 = Transformer.to(StudentVIO2.class).apply(studentVIO).done();
        return ApiResponse.createSuccess(studentVIO2);
    }

    @ApiOperation("获取学生信息(根据定义的类编集一个普通类对象)")
    @GetMapping("/student3")
    public ApiResponse<StudentVCO> getStudent3(){
        Student student = new Student();
        student.setSid(1L);
        student.setName("张三");
        StudentVCO studentVCO = Transformer.to(StudentVCO.class).apply(student).done();
        return ApiResponse.createSuccess(studentVCO);
    }

    @ApiOperation("获取学生信息(根据定义的类多重编集一个普通类对象)")
    @GetMapping("/student4")
    public ApiResponse<StudentVCO3> getStudent4(){
        Student student = new Student();
        student.setSid(1L);
        student.setName("张三");
        StudentVCO studentVCO = Transformer.to(StudentVCO.class).apply(student).done();
        StudentVCO2 studentVCO2 = Transformer.to(StudentVCO2.class).apply(studentVCO).done();
        StudentVCO3 studentVCO3 = Transformer.to(StudentVCO3.class).apply(studentVCO2).done();
        return ApiResponse.createSuccess(studentVCO3);
    }

    @ApiOperation("获取学生信息(通过接口定义编集Transform4j的代理对象)")
    @GetMapping("/student5")
    public ApiResponse<StudentVIO3> getStudent5(){
        Student student = new Student();
        student.setSid(1L);
        student.setName("张三");
        StudentVCO studentVCO = Transformer.to(StudentVCO.class).apply(student).done();
        StudentVIO3 studentVIO3 = Transformer.to(StudentVIO3.class).apply(studentVCO).done();
        return ApiResponse.createSuccess(studentVIO3);
    }

    @ApiOperation("获取学生信息(通过类定义编集接口匿名对象)")
    @GetMapping("/student6")
    public ApiResponse<StudentVCO4> getStudent6(){
        StudentVIO studentVIO = new StudentVIO() {
            @Override
            public Long getId() {
                return 1L;
            }

            @Override
            public String getName() {
                return "里斯";
            }
        };
        StudentVCO4 studentVCO4 = Transformer.to(StudentVCO4.class).apply(studentVIO).done();
        return ApiResponse.createSuccess(studentVCO4);
    }

    @ApiOperation("获取学生信息(通过接口定义编集抽象类匿名对象)")
    @GetMapping("/student7")
    public ApiResponse<StudentVIO4> getStudent7(){
        AbstractStudent student = new AbstractStudent() {
            @Override
            public Long getId() {
                return 1L;
            }

            @Override
            public String getName() {
                return "大黄蜂";
            }

        };
        StudentVIO4 studentVIO4 = Transformer.to(StudentVIO4.class).apply(student).done();
        return ApiResponse.createSuccess(studentVIO4);
    }

}
